package io.renren.modules.member.service.impl;

import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import io.renren.common.utils.CommonUtils;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.modules.member.dao.V9MemberDao;
import io.renren.modules.member.entity.V9MemberEntity;
import io.renren.modules.member.service.V9MemberService;

@Service("v9MemberService")
public class V9MemberServiceImpl extends ServiceImpl<V9MemberDao, V9MemberEntity> implements V9MemberService {
    @Autowired
    V9MemberDao v9MemberDao;
    @Autowired
    V9MemberService v9MemberService;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String phpssouid = (String) params.get("phpssouid");
        String is_lock = (String) params.get("is_lock");
        String vip = (String) params.get("vip");
        String start = (String) params.get("start");
        String end = (String) params.get("end");
        String username = (String) params.get("username");
        String userid = (String) params.get("userid");
        String email = (String) params.get("email");
        String regip = (String) params.get("regip");
        String nickname = (String) params.get("nickname");
        String type = (String) params.get("type");// 0 用户名 1 用户id 2邮箱 3注册ip 4昵称
        String value = (String) params.get("value");

        QueryWrapper<V9MemberEntity> queryWrapper = new QueryWrapper<>();
        if (StringUtils.isNotBlank(type)) {
            if ("0".equals(type)) {
                queryWrapper.like("username", "%" + value + "%");
            }
            if ("1".equals(type)) {
                queryWrapper.like("userid", "%" + value + "%");
            }
            if ("2".equals(type)) {
                queryWrapper.like("email", "%" + value + "%");
            }
            if ("3".equals(type)) {
                queryWrapper.like("regip", "%" + value + "%");
            }
            if ("4".equals(type)) {
                queryWrapper.like("nickname", "%" + value + "%");
            }

        }
        Integer sInteger=0,eInteger=0;
        Integer status1 = null;
        Integer status = null;
        if (StringUtils.isNotBlank(start)) {
            sInteger= CommonUtils.timeStrToTimeStamp3(start);
            eInteger=CommonUtils.timeStrToTimeStamp3(end);
        }
        if (StringUtils.isNotBlank(vip)) {
            status1 = Integer.parseInt(vip);
        }
        if (StringUtils.isNotBlank(is_lock)) {
            status = Integer.parseInt(is_lock);
        }
        IPage<V9MemberEntity> page = this.page(
                new Query<V9MemberEntity>().getPage(params, "userid", false),
                queryWrapper
                        .like(StringUtils.isNotBlank(username), "username", "%" + username + "%")
                        .like(StringUtils.isNotBlank(userid), "userid", "%" + userid + "%")
                        .like(StringUtils.isNotBlank(email), "email", "%" + email + "%")
                        .like(StringUtils.isNotBlank(regip), "regip", "%" + regip + "%")
                        .like(StringUtils.isNotBlank(nickname), "nickname", "%" + nickname + "%")
                        .like(StringUtils.isNotBlank(phpssouid), "phpssouid", "%" + phpssouid + "%")
                        .like(StringUtils.isNotBlank(is_lock), "is_lock", "%" + is_lock + "%")
                        .like(StringUtils.isNotBlank(vip), "vip", "%" + vip + "%")
                        .eq(status != null, "is_lock", is_lock)
                        .eq(status1 != null, "vip", vip)
                        .between(StringUtils.isNotBlank(start), "regdate", sInteger, eInteger));

        return new PageUtils(page);
    }

    @Override
    public int getPhpssouid() {
        return v9MemberDao.getPhpssouid();
    }

	@Override
	public Integer inserGetId(V9MemberEntity memberEntity) {
		baseMapper.insert(memberEntity);
		return memberEntity.getUserid();
		
	}

    /*@Override
    public boolean doRegister(String username, String password, String email,String code) {
        Properties properties = new Properties();
        properties.setProperty("mail.smtp.host",HOST);//
        return false;
    }*/

}
